<!-- 新增配种记录 -->
<template>
	<view class="header">
		<view class="title">
			牧民信息 （操作员）
		</view>
		<uni-list>
			<view class="item">
				<uni-list-item title="牧民姓名"></uni-list-item>
				<uv-input placeholder="请输入牧民姓名" inputAlign="right" border="none" v-model="farmerInfo.name"></uv-input>
			</view>
			<view class="item">
				<uni-list-item title="联系电话"></uni-list-item>
				<uv-input placeholder="请输入联系电话" inputAlign="right" border="none" v-model="farmerInfo.phone"></uv-input>
			</view>
			<view class="item">
				<uni-list-item title="地址"></uni-list-item>
				<uv-input placeholder="请输入地址" inputAlign="right" border="none" v-model="farmerInfo.address"></uv-input>
			</view>
		</uni-list>
		<view class="title">
			选择配种对象
		</view>
		<uni-list>
			<view class="item">
				<uni-list-item title="选择公牛"></uni-list-item>
				<uv-input placeholder="请输入公牛ID" inputAlign="right" border="none"
					v-model="livestock.bullImei"></uv-input>
			</view>
			<view class="item">
				<uni-list-item title="选择母牛"></uni-list-item>
				<uv-input placeholder="请输入母牛ID" inputAlign="right" border="none" v-model="livestock.cowImei"></uv-input>
			</view>
		</uni-list>
		<view class="title1">
			<view>备注：</view>
			<textarea class="remark-input" placeholder="请输入备注信息" auto-height :maxlength="-1"
				v-model="remark"></textarea>
		</view>
		<button class="btn" @click="submitForm">提交</button>
	</view>
</template>

<script setup>
	import {
		ref,
		onMounted
	} from 'vue';
	import {
		addBreed
	} from '@/utils/api/Management.js'
	// 牧民信息
	const farmerInfo = ref({
		name: '',
		phone: '',
		address: ''
	});

	// 牲畜信息
	const livestock = ref({
		bullImei: '',
		cowImei: ''
	});

	// 备注
	const remark = ref('');
	const calendarRef = ref(null);

	// 提交表单
	const submitForm = async () => {
		const formData = {
			F_UserName: farmerInfo.value.name,
			F_Phone: farmerInfo.value.phone,
			F_Address: farmerInfo.value.address,
			F_PaternalLine: livestock.value.bullImei,
			F_Matriarchal: livestock.value.cowImei,
			F_Remark: remark.value
		};
		console.log('提交的数据:', formData);
		let res = await addBreed(formData)
		if (res.code == 200) {
			uni.showToast({
				title: '提交成功',
				icon: 'success',
				duration: 1500, // 1.5秒后自动关闭
				success: () => {
					// ✅ 提交成功后，1.5秒后返回上一页
					setTimeout(() => {
						uni.navigateBack();
					}, 1500);
				}
			});
		}
	};
</script>

<style scoped>
	.header {
		width: 100%;
		height: 95vh;
		position: relative;
		display: flex;
		flex-direction: column;
	}

	.title {
		height: 60rpx;
		width: 100%;
		background-color: #EFEFEF;
		padding-left: 20rpx;
		line-height: 60rpx;
	}

	.title1 {
		height: auto;
		width: 100%;
		padding: 20rpx;
		display: flex;
		align-items: flex-start;
	}

	.remark-input {
		flex: 1;
		min-height: 120rpx;
		padding: 10rpx;
		border: 1rpx solid #eee;
		border-radius: 8rpx;
		line-height: 1.5;
	}

	.item {
		display: flex;
		border: 2rpx solid #eee;
	}

	.btn {
		width: 100%;
		height: 90rpx;
		background-color: #0BCB75;
		position: absolute;
		bottom: 0;
	}
</style>